const WXAPI = require('../../wxapi/main')
// const WXAPI = require('apifm-wxapi')
// const TOOLS = require('../../utils/tools.js')
// const AUTH = require('../../utils/auth')
// const CONFIG = require('../../config.js')

var t = getApp()

Page({
    data: {
        isIpx: t.globalData.isIpx,
        storeId: "",
        disabledScroll: !1,
        imgwidth: 0,
        imgheight: 0,
        categories: [],
        themeGroups: [],
        gallery: {},
        defaultBanners: [],
        artworkTabs: [],
        indicatorDots: !1,
        autoplay: !1,
        interval: 5e3,
        duration: 1e3,
        packageLoaded: 1,
        zxlb: [],
        searchName: "",
        index1: 'https://dcdn.it120.cc/2025/07/04/8a523359-399f-490b-bc0f-3cf2da8d5d2a.gif',
        index2: 'https://dcdn.it120.cc/2025/07/04/d226d38b-251d-4b6d-a35a-553e64eeda1e.jpg',
        index3: 'https://dcdn.it120.cc/2025/07/04/d5933a6b-d0cd-4cc1-9eb8-d5ca9f801b6d.jpg', index4: 'https://dcdn.it120.cc/2025/07/04/bc267f57-1c70-4231-a9b0-4e55c97d20eb.jpg',
        index5: 'https://dcdn.it120.cc/2025/07/04/0ef3be16-c864-4de2-8347-09d30b5e6111.jpg',
        md: {},
        showUp: false,
        fxtp: wx.getStorageSync('fxtp') || '',

    },





    onLoad: function (e) {
        const that = this;
        //banner
        WXAPI.banners({
            type: 'banner'
        }).then(function (res) {
            if (res.code == 700) {
                wx.showModal({
                    title: '提示',
                    content: '请在后台添加 banner 轮播图片，自定义类型填写 banner',
                    showCancel: false
                })
            } else {
                wx.setStorageSync('njbanner', res.data);
                that.setData({
                    defaultBanners: res.data
                });
            }
        }).catch(function (e) {
            wx.showToast({
                title: res.msg,
                icon: 'none'
            })
        })

        WXAPI.shopSubdetail(1020624).then(function (res) {
            console.log("shopSubdetail", res.data);
            that.setData({
                md: res.data,
                index1: res.data.info.introduce,
                index2: res.data.info.businessScope,
                index4: res.data.info.pic,
                index5: res.data.info.logo
            });
        }).catch(function (e) {
            wx.showToast({
                title: res.msg,
                icon: 'none'
            })
        })

    },


    // 侧栏
    tel: function () {
        wx.makePhoneCall({
            phoneNumber: wx.getStorageSync('shopSubdetail').info.linkPhone,
        })
    },
    sc: function () {
        wx.navigateTo({
            url: '/pages/index/sc'
        })
    },
    onPageScroll: function (e) {
        // 页面滚动时触发
        // console.log('页面滚动，当前滚动位置：', e.scrollTop);
        if (e.scrollTop > 100) {
            this.setData({
                showUp: true
            })
        } else {
            this.setData({
                showUp: false
            })
        }
    },
    up: function () {
        //   点击返回顶部
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
        })
    },



    golist: function (e) {
        wx.navigateTo({
            url: '/pages/index/list?id=' + e.currentTarget.dataset.id
        })
    },

    gomy: function () {
        wx.navigateTo({
            url: '/pages/index/my'
        })
    },

    gomap: function () {
        wx.openLocation({
            latitude: this.data.md.info.latitude,
            longitude: this.data.md.info.longitude,
            scale: 18,
            name: this.data.md.info.name,
            address: this.data.md.info.address
        })
    },

    imageLoad: function (e) {
        var $width = e.detail.width; //获取图片真实宽度
        var $height = e.detail.height; //获取图片真实高度
        this.setData({
            imgwidth: $width,
            imgheight: $height
        })
    },


    onShow: function () { },
    onHide: function () { },
    onUnload: function () { },
    onPullDownRefresh: function () { },
    onReachBottom: function () { },

    // 分享
    onShareAppMessage: function () {
        return {
            title: "GOOD STUDIO儿童摄影",
            imageUrl: this.data.fxtp,
            path: "/pages/index/index"
        };
    },

    onShareTimeline: function () {
        return {
            title: "GOOD STUDIO儿童摄影",
            imageUrl: this.data.fxtp,
        }
    },

    // 点击幻灯片
    gotoBannerLink: function (t) {
        var a = t.currentTarget.dataset.link;
        console.log("banner link", a);
        // console.info("open link", a), a && (a.includes("https://mp.weixin.qq.com") || a.includes("Good.cn")) && wx.navigateTo({
        //     url: "/pages/webview/webview?link=" + a
        // });
        if(t.currentTarget.dataset.link) {
            console.log("cc",a);
            
            wx.navigateTo({
                url: a
            });
        }


    },


    tapCampaignSplash: function () {
        t.campaignEventLog("click_splash"), console.log("tapCampaignSplash"), this.setData({
            showCampaignSplash: !1
        });
    },

    onPreviewSlides: function (t) {
        t.currentTarget.dataset.url;
        var a = t.currentTarget.dataset.category;
        t.currentTarget.dataset.package;
        wx.navigateTo({
            url: "/pages/product-detail/product-detail?category_id=" + a,
            success: function (t) { },
            fail: function (t) { },
            complete: function (t) { }
        });
    },
    loadThemePhotos: function (t) {
        var a = t.currentTarget.dataset.id;
        console.log("e.currentTarget.dataset", t.currentTarget.dataset), wx.navigateTo({
            url: "/pages/themes/themes?category_id=" + a,
            success: function (t) { },
            fail: function (t) { },
            complete: function (t) { }
        });
    },
    loadMorePhotos: function (t) {
        var a = t.currentTarget.dataset.category;
        t.currentTarget.dataset.package;
        wx.navigateTo({
            url: "/pages/product-detail/product-detail?category_id=" + a,
            success: function (t) { },
            fail: function (t) { },
            complete: function (t) { }
        });
    },
    gotoProductDetail: function (t) {
        // var a = t.currentTarget.dataset.categoryid;
        // wx.navigateTo({
        //     url: "/pages/product-detail/product-detail?category_id=" + a + "&type=nj",
        //     success: function(t) {},
        //     fail: function(t) {},
        //     complete: function(t) {}
        // });
    },
    onSwitchTab: function (t) {
        wx.navigateTo({
            url: "/pages/product-detail/product-detail?category_id=" + a + "&type=nj",
            success: function (t) { },
            fail: function (t) { },
            complete: function (t) { }
        });

        var a = t.currentTarget.dataset.categoryid;
        wx.navigateTo({
            url: "/pages/product-detail/product-detail?category_id=" + a + "&type=nj",
            success: function (t) { },
            fail: function (t) { },
            complete: function (t) { }
        });
    },
    searchNameChange(e) {    //e  就是wxml中的value

        this.setData({
            searchName: e.detail.value,
        })
    },
    wx_kj() {
        console.log(11111);
        wx.navigateTo({
            url: "/pages/kj/ages",
        });
    },
    wx_pt() {
        console.log(11111);
        wx.navigateTo({
            // url: "/pages/goodsdetails/goodsdetails",
            url: "/pages/goods-details/index",

        });
    },
    search() {
        console.log(11111, this.data.searchName);
        wx.navigateTo({
            url: "/pages/zxss/zx?name=" + this.data.searchName,
        });
    },
    gotozx: function () {
        wx.navigateTo({
            url: "/pages/zx/zx",
            success: function (t) { },
            fail: function (t) { },
            complete: function (t) { }
        });
    },

    gotozx2: function (e) {
        let a = e.currentTarget.dataset.categoryid;
        if (e.currentTarget.dataset.categoryid2) {
            wx.navigateTo({
                url: "/pages/zx/zx?tab=" + a + "&tab2=" + e.currentTarget.dataset.categoryid2 + "&link=" + e.currentTarget.dataset.link,
                success: function (t) { },
                fail: function (t) { },
                complete: function (t) { }
            });
        } else {
            wx.navigateTo({
                url: "/pages/zx/zx?tab=" + a + "&link=" + e.currentTarget.dataset.link,
                success: function (t) { },
                fail: function (t) { },
                complete: function (t) { }
            });
        }

    },

});